package com.ruoyi.bizsys.controller;

import com.ruoyi.bizsys.query.AwardConfigQuery;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.bizsys.domain.AwardConfig;
import com.ruoyi.bizsys.service.IAwardConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 奖励配置Controller
 *
 * @author african-loan
 * @date 2022-06-22
 */
@RestController
@RequestMapping("/award/config")
public class AwardConfigController extends BaseController {
    @Autowired
    private IAwardConfigService awardConfigService;

    /**
     * 查询奖励配置列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:config:list')")
    @GetMapping("/list")
    public TableDataInfo list(AwardConfigQuery awardConfigQuery) {
        startPage();
        List<AwardConfig> list = awardConfigService.selectAwardConfigList(awardConfigQuery);
        return getDataTable(list);
    }

    /**
     * 导出奖励配置列表
     */
    @PreAuthorize("@ss.hasPermi('bizsys:config:export')")
    @Log(title = "奖励配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AwardConfigQuery awardConfigQuery) {
        List<AwardConfig> list = awardConfigService.selectAwardConfigList(awardConfigQuery);
        ExcelUtil<AwardConfig> util = new ExcelUtil<AwardConfig>(AwardConfig.class);
        return util.exportExcel(list, "config");
    }

    /**
     * 获取奖励配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('bizsys:config:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(awardConfigService.selectAwardConfigById(id));
    }

    /**
     * 新增奖励配置
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('bizsys:config:add')")
    @Log(title = "奖励配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AwardConfig awardConfig) {
        return toAjax(awardConfigService.insertAwardConfig(awardConfig));
    }

    /**
     * 修改奖励配置
     */
    @PreAuthorize("@ss.hasPermi('bizsys:config:edit')")
    @Log(title = "奖励配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AwardConfig awardConfig) {
        return toAjax(awardConfigService.updateAwardConfig(awardConfig));
    }

    /**
     * 删除奖励配置
     */
    @PreAuthorize("@ss.hasPermi('bizsys:config:remove')")
    @Log(title = "奖励配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(awardConfigService.deleteAwardConfigByIds(ids));
    }
}
